package com.dd.stack.redis.controller;

import com.dd.stack.common.util.response.ApiResponse;
import com.dd.stack.common.util.Result;
import com.dd.stack.redis.pojo.DO.DataObjectDO;
import com.dd.stack.redis.service.inner.impl.DataObjectServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/1/28 16:20
 * @Description DataObjectController
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "DataObjectController")
@RequestMapping("/data-objects")
public class DataObjectController {

    private final DataObjectServiceImpl dataObjectService;

    @PostMapping("/add")
    @ApiOperation("新增 DataObjectDO 对象")
    public Result addDataObject(@RequestBody DataObjectDO dataObjectDO) {
        dataObjectService.addDataObject(dataObjectDO);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据 ID 获取 DataObjectDO 对象")
    public ApiResponse<DataObjectDO> getDataObject(@PathVariable Long id) {
        return ApiResponse.success(dataObjectService.getById(id));
    }

    @GetMapping("/all")
    @ApiOperation("获取所有DataObjectDO对象")
    public ApiResponse<List<DataObjectDO>> all() {
        return ApiResponse.success(dataObjectService.all());
    }

    @PutMapping
    @ApiOperation("根据 ID 更新 DataObjectDO 对象")
    public Result updateDataObject(@RequestBody DataObjectDO dataObjectDO) {
        return dataObjectService.updateDataObject(dataObjectDO);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据 ID 删除 DataObjectDO 对象")
    public Result deleteDataObject(@PathVariable Long id) {
        return dataObjectService.deleteDataObject(id);
    }
}